package com.dy.design_pattern_study.composite_pattern.dome1;

import com.dy.design_pattern_study.composite_pattern.dome1.impl.Composite;
import com.dy.design_pattern_study.composite_pattern.dome1.impl.Leaf;

/**
 * @CreateBy zhangdingyi
 * @Date 2023-04-12
 * @Content
 */
public class client {
    public static void main(String[] args) {
        //生成根节点 root，其下属有 两个子叶节点 A B
        Component root = new Composite("root");
        root.add(new Leaf("Leaf A"));
        root.add(new Leaf("Leaf B"));

        //根节点继续长出分支，Composite X 分支有子叶节点 XA XB
        Component comp = new Composite("Composite X");
        comp.add(new Leaf("Leaf XA"));
        comp.add(new Leaf("Leaf XB"));
        root.add(comp);

        //根节点继续长出分支，Composite XY 分支有子叶节点 XYA XYB
        Component comp1 = new Composite("Composite XY");
        comp1.add(new Leaf("Leaf XYA"));
        comp1.add(new Leaf("Leaf XYB"));
        root.add(comp1);

        //根节点分别长出 两叶节点
        root.add(new Leaf("Leaf C"));

        Leaf leaf_d = new Leaf("Leaf D");
        root.add(leaf_d);
        root.remove(leaf_d);

        //显示大树的整体面貌
        root.display(1);
    }
}
